package cn.edu.bupt.ch5_1.controller;

import cn.edu.bupt.ch5_1.entity.Person;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@RestController
public class HelloController {

    @GetMapping(value = "/hello/{name}")
    public String SayHello(@PathVariable String name) {
        return "Hello " + name;
    }

    @GetMapping(value = "/mv-demo")
    public ModelAndView MVDemo() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("result");
        Person person = new Person();
        person.setName("小强");
        person.setAge(20);
        mv.addObject("person", person);
        return mv;
    }

    @GetMapping(value = "/json-demo")
    public Person jsonDemo() {
        Person person = new Person();
        person.setName("小强");
        person.setAge(20);
        return person;
    }}